#!/bin/bash

# syncs my music dirs in ~ and external drives

PRIMARY="$HOME/Music/"
SECONDARY="/media/Dragis_HDD/Music/"

NICENESS=10
LOGFILE="$HOME/.syncmusic.log"

RSYNC_OPTS="-rltHh"
if [[ $1 != '-q' ]]; then
	RSYNC_OPTS="--verbose --progress $RSYNC_OPTS"
fi

[[ $1 != '-q' ]] && echo "Stage 1: Syncing $PRIMARY to $SECONDARY..."
nice -n $NICENESS rsync $RSYNC_OPTS --numeric-ids $PRIMARY $SECONDARY 2> $LOGFILE

[[ $1 != '-q' ]] && echo "Stage 2: Syncing $SECONDARY to $PRIMARY..."
nice -n $NICENESS rsync $RSYNC_OPTS --numeric-ids $SECONDARY $PRIMARY 2>> $LOGFILE

if [ -s $LOGFILE ]; then
	echo "Something went wrong while syncing music dirs. Review the logfile \
($LOGFILE) to see details." >&2
	exit 127
else
	[[ $1 != '-q' ]] && echo "Music synced successfully. Woohoo!"
fi
